#随机森林
from sklearn.datasets import load_iris 
from sklearn.model_selection import train_test_split 
from sklearn.ensemble import RandomForestclassifier 
from sklearn.metrics import accuracy_score 
from sklearn.model_selection import cross_val_score 
import matplotlib.pyplot as plt 
from matplotlib.colors import Listedcolormap 
import numpy as np 
#导入并拆分数据集
dataset = load_iris()
x,y- dataset.data, dataset. target 
x_train, x_test, y_train, y_test=train_test_split(x, y,random_state=0, test_size=50) 
#训练模型
model=RandomForestclassifier(n estimators=10, random state-0) 
model.fit(x_train, y_train) 
#评估模型
pred=model.predict(x_test) 
ac =accuracy_score(y_test pred) 
print(f'随机森林模型的准确率:{ac}')